/**
 * 字典类型列表界面。
 * @author linzongxue
 * @create_date 2012-2-15
 */
define(function(){
	var TypeGridPanel = Ext.extend(Ext.grid.GridPanel, {
		border: false,
		stripeRows: true,
	    enableHdMenu: false,
	    autoExpandColumn: 4,
	    loadMask: {msg: '正在加载数据...'},
		initComponent: function(){
			TypeGridPanel.superclass.initComponent.call(Ext.apply(this, {
				store: new Ext.data.JsonStore({
				    idProperty: 'id', fields: ['name', 'text', 'memo'],
				    url: 'sys/dict/getAllDictTypes.do'
				}),
				columns: [
					new Ext.grid.RowNumberer(),
				    this.sm = new Ext.grid.CheckboxSelectionModel(),
					{header: '名称', width: 120, dataIndex: 'name'},
					{header: '标题', width: 140, dataIndex: 'text'},
					{header: '说明', width: 150, dataIndex: 'memo'} //auto width
				]
			}));
			this.on({
				afterrender: function(){
					this.store.load();
				},
				rowdblclick: function(){
					if(au.permit('sys.dict.modify')) this.ownerCt.modifyDictType();
				}
			});
			this.getSelectionModel().on({
				rowselect: function(sm, i, record){
					//选中的类型改变后，触发主界面的方法
					this.ownerCt.changeType(record.json);
				},
				rowdeselect: function(sm, i, record){
					if (sm.getSelections().length == 0){
						this.ownerCt.changeType(null);
					}
				},
				scope: this
			});
		},
		insertNewRow: function(data){
			this.store.loadData(data, true);
            this.getSelectionModel().selectLastRow();
		}
	});
	return TypeGridPanel;
});